package com.example.client.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wangxianchen
 * @create 2017-12-25
 * @desc
 */
@Controller
public class DemoController {
    private static Logger logger = LoggerFactory.getLogger(DemoController.class);

    @Value("${spring.application.name:null}")
    String appName;

    @Value("${spring.cloud.config.profile:null}")
    String profile;

    @Value("${spring.cloud.config.label:null}")
    String label;

    @Value("${spring.profiles.active:null}")
    String active;


    @RequestMapping("/status")
    public String status(HttpServletRequest request, ModelMap modelMap){
        modelMap.put("appName",appName);
        modelMap.put("profile",profile);
        modelMap.put("label",label);
        modelMap.put("active",active);
        return "statusInfo";
    }

    @RequestMapping(value = "/hi",method = RequestMethod.GET)
    @ResponseBody
    public String hi(@RequestParam String name){
        return "welcome to "+appName+" service, "+name;
    }

}
